﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Text;
using Chenxin.Lib.Passport.Entity;
using System.Collections.Generic;

public partial class ShowDetailInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            //房屋ID
            string strHouseId = Context.Request.Params["houseid"];

            if (string.IsNullOrEmpty(strHouseId))
            {
                Context.Response.Redirect(string.Format("/errorpage.aspx?msg={0}", "房源ID不存在"));
            }

            //取得房源基本信息
            Chenxin.Lib.House.Entity.House_BaseInfo entHouseBaseInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetHouseInfoEntity(strHouseId);

            //没有相应ID的信息
            if (Guid.Empty.Equals(entHouseBaseInfo.HouseId))
            {
                Context.Response.Redirect(string.Format("/errorpage.aspx?msg={0}", "房源信息不存在"));
            }

            //隐藏房屋Id的设定
            hidHouseId.Value = strHouseId;

            //标题设定
            setTitle(entHouseBaseInfo);

            //经纪人信息设定
            setBrokerInfo(entHouseBaseInfo.AddPersonId);

            //房源详情设定
            setHouseDetailInfo(entHouseBaseInfo);

            //看过房源业主的人的信息
            setViewOwnerInfo(strHouseId);

            //房源配置
            if (!string.IsNullOrEmpty(entHouseBaseInfo.BaseEquip))
            {
                lbBaseEquip.Text = entHouseBaseInfo.BaseEquip.Replace("\\n", "<br>");
            }
            //备注
            if (!string.IsNullOrEmpty(entHouseBaseInfo.Remarks))
            {
                lbRemarks.Text = entHouseBaseInfo.Remarks.Replace("\\n", "<br>");
            }

            //隐藏房源信息
            setHidHouseInfo(entHouseBaseInfo);
            setHousePic(strHouseId);
        }
        catch (Exception ex)
        {
            Response.Redirect("/errorpage.aspx?msg=" + ex.Message);
        }
    }

    private void setTitle(Chenxin.Lib.House.Entity.House_BaseInfo entHouseBaseInfo)
    {
        //状态
        StringBuilder strStatue = new StringBuilder();
        //标题
        StringBuilder strTitle = new StringBuilder();
        strStatue.Append("【");
        if (entHouseBaseInfo.Status == 10)
        {
            strStatue.Append("有效");
        }
        else if (entHouseBaseInfo.Status == -10)
        {
            strStatue.Append("无效");
        }
        else
        {
            strStatue.Append("暂缓");
        }
        strStatue.Append("】");

        strTitle.Append(entHouseBaseInfo.Community);
        strTitle.Append(entHouseBaseInfo.BuildingName);
        strTitle.Append(entHouseBaseInfo.Room);
        strTitle.Append(",");
        strTitle.Append(entHouseBaseInfo.Model_Room);
        strTitle.Append("室");
        strTitle.Append(entHouseBaseInfo.Model_Hall);
        strTitle.Append("厅");
        strTitle.Append(entHouseBaseInfo.Model_Toilet);
        strTitle.Append("卫");
        strTitle.Append(entHouseBaseInfo.Model_Balcony);
        strTitle.Append("阳台, ");

        if (entHouseBaseInfo.BusinessKind == 10)
        {
            strTitle.Append("售价:");
            if (entHouseBaseInfo.SalePrice_T == 0 || entHouseBaseInfo.SalePrice_T == null)
            {
                strTitle.Append("--");
            }
            else
            {
                strTitle.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.SalePrice_T / 10000, 2)) + "万");
            }
        }
        else if (entHouseBaseInfo.BusinessKind == 20)
        {
            strTitle.Append("租价:");
            if (entHouseBaseInfo.RentPrice == 0 || entHouseBaseInfo.RentPrice == null)
            {
                strTitle.Append("--");
            }
            else
            {
                strTitle.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.RentPrice, 2)) + "(元/月)");
            }
        }
        else if (entHouseBaseInfo.BusinessKind == 30)
        {
            strTitle.Append("售价:");
            if (entHouseBaseInfo.SalePrice_T == 0 || entHouseBaseInfo.SalePrice_T == null)
            {
                strTitle.Append("--");
            }
            else
            {
                strTitle.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.SalePrice_T / 10000, 2)) + "万");
            }
            strTitle.Append("租价:");
            if (entHouseBaseInfo.RentPrice == 0 || entHouseBaseInfo.RentPrice == null)
            {
                strTitle.Append("--");
            }
            else
            {
                strTitle.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.RentPrice, 2)) + "(元/月)");
            }
        }

        //状态
        lbStatue.Text = strStatue.ToString();
        //标题
        lbTitle.Text = strTitle.ToString();

    }

    private void setBrokerInfo(Guid BrokerId)
    {
        //取得经纪人相关信息
        Hr_UserInfo entUserInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetAddPersonInfo(BrokerId);

        if (Guid.Empty.Equals(entUserInfo.UserId))
        {
            //经纪人头像
            imgHead.ImageUrl = "/images/jw.jpg";
        }
        else
        {
            //经纪人头像
            if (string.IsNullOrEmpty(entUserInfo.PicUrl))
            {
                imgHead.ImageUrl = "/images/jw.jpg";
            }
            else
            {
                imgHead.ImageUrl = entUserInfo.PicUrl;
            }
            //经纪人名
            lbBroker.Text = entUserInfo.UserName;
            //经纪人所属部门
            lbBrokerDepartNm.Text = entUserInfo.DepartName;
            //经纪人手机号
            lbBrokerMobile.Text = entUserInfo.Mobile;
        }
    }

    private void setHouseDetailInfo(Chenxin.Lib.House.Entity.House_BaseInfo entHouseBaseInfo)
    {
        StringBuilder strHouseInfo = new StringBuilder();
        strHouseInfo.Append("<ul>");
        strHouseInfo.Append("<li class=\"wid1 fl\">房源所在： " + entHouseBaseInfo.Community + entHouseBaseInfo.BuildingName + entHouseBaseInfo.Room + " </li>");
        strHouseInfo.Append("<li class=\"wid2 fl\">房源编号： " + entHouseBaseInfo.HouseCode + " </li>");
        strHouseInfo.Append("<li class=\"wid1 fl\">小区地址： " + entHouseBaseInfo.Address + " </li>");
        strHouseInfo.Append("<li class=\"wid2 fl\">交易： ");
        if (entHouseBaseInfo.BusinessKind == 20)
        {
            strHouseInfo.Append("出租");
        }
        else if (entHouseBaseInfo.BusinessKind == 10)
        {
            strHouseInfo.Append("出售");
        }
        else
        {
            strHouseInfo.Append("租售");
        }
        strHouseInfo.Append("</li>");
        strHouseInfo.Append("<li class=\"wid1 fl\">区域： " + entHouseBaseInfo.Region + "</li>");
        strHouseInfo.Append("<li class=\"wid2 fl\">板块：" + entHouseBaseInfo.Block + "</li>");

        strHouseInfo.Append("<li class=\"wid1 fl\">用途： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.HouseUse))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.HouseUse);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2 fl\">类型： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.BuildingType))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.BuildingType);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid1 fl\">竣工年份： ");
        if (entHouseBaseInfo.CompleteYear == null || entHouseBaseInfo.CompleteYear == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.CompleteYear) + "年");
        }
        strHouseInfo.Append("</li>");

        if (entHouseBaseInfo.BusinessKind == 10 || entHouseBaseInfo.BusinessKind == 30)
        {
            strHouseInfo.Append("<li class=\"wid2 fl\">售总价： ");
            if (entHouseBaseInfo.SalePrice_T == 0 || entHouseBaseInfo.SalePrice_T == null)
            {
                strHouseInfo.Append("--");
            }
            else
            {
                strHouseInfo.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.SalePrice_T / 10000, 2)) + "万");
            }
            strHouseInfo.Append("</li>");

            strHouseInfo.Append("<li class=\"wid1 fl\">售单价： ");
            if (entHouseBaseInfo.SalePrice_U == 0 || entHouseBaseInfo.SalePrice_U == null)
            {
                strHouseInfo.Append("--");
            }
            else
            {
                strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.SalePrice_U) + "元/㎡");
            }
            strHouseInfo.Append("</li>");

            strHouseInfo.Append("<li class=\"wid2 fl\">售底价： ");
            if (entHouseBaseInfo.SalePrice_R == 0 || entHouseBaseInfo.SalePrice_R == null)
            {
                strHouseInfo.Append("--");
            }
            else
            {
                strHouseInfo.Append(Convert.ToString(Math.Round((decimal)entHouseBaseInfo.SalePrice_R / 10000, 2)) + "万");
            }
            strHouseInfo.Append("</li>");
        }

        if (entHouseBaseInfo.BusinessKind == 20 || entHouseBaseInfo.BusinessKind == 30)
        {
            strHouseInfo.Append("<li class=\"wid1 fl\">租总价： ");
            if (entHouseBaseInfo.RentPrice == 0 || entHouseBaseInfo.RentPrice == null)
            {
                strHouseInfo.Append("--");
            }
            else
            {
                strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.RentPrice) + "元/月");
            }
            strHouseInfo.Append("</li>");

            strHouseInfo.Append("<li class=\"wid2 fl\">租底价： ");
            if (entHouseBaseInfo.RentPrice_R == 0 || entHouseBaseInfo.RentPrice_R == null)
            {
                strHouseInfo.Append("--");
            }
            else
            {
                strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.RentPrice_R) + "元/月");
            }
            strHouseInfo.Append("</li>");

            strHouseInfo.Append("<li class=\"wid2 fl\">合租/支付：");
            if (entHouseBaseInfo.IsGroup)
            {
                strHouseInfo.Append("是");
            }
            else
            {
                strHouseInfo.Append("否");
                if (string.IsNullOrEmpty(entHouseBaseInfo.PayMode))
                {
                    strHouseInfo.Append("--");
                }
                else
                {
                    strHouseInfo.Append(entHouseBaseInfo.PayMode);
                }
            }
            strHouseInfo.Append("</li>");
        }

        strHouseInfo.Append("<li class=\"wid2a fl\">面积： ");
        if (entHouseBaseInfo.BuildingArea == null || entHouseBaseInfo.BuildingArea == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.BuildingArea) + "㎡");
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2b fl\">房型： ");
        if (entHouseBaseInfo.Model_Room == null || entHouseBaseInfo.Model_Room == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Model_Room) + "室");
        }
        if (entHouseBaseInfo.Model_Hall == null || entHouseBaseInfo.Model_Hall == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Model_Hall) + "厅");
        }
        if (entHouseBaseInfo.Model_Toilet == null || entHouseBaseInfo.Model_Toilet == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Model_Toilet) + "卫");
        }
        if (entHouseBaseInfo.Model_Balcony == null || entHouseBaseInfo.Model_Balcony == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Model_Balcony) + "阳台");
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">朝向： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.Direction))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.Direction);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">层高： ");
        if (entHouseBaseInfo.Cur_Floor == null || entHouseBaseInfo.Cur_Floor == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Cur_Floor));
        }
        strHouseInfo.Append("/");
        if (entHouseBaseInfo.Total_Floor == null || entHouseBaseInfo.Total_Floor == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.Total_Floor));
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2b fl\">现状： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.Actuality))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.Actuality);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">装修情况： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.Fitment))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.Fitment);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">租约： ");
        if (entHouseBaseInfo.HavRentContract)
        {
            strHouseInfo.Append("有");
        }
        else
        {
            strHouseInfo.Append("无");
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2b fl\">产权： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.Property))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.Property);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">来源： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.InfoSource))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.InfoSource);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">钥匙： ");
        if (entHouseBaseInfo.IsHavekey)
        {
            strHouseInfo.Append("有");
        }
        else
        {
            strHouseInfo.Append("无");
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2b fl\">委托： ");
        if (entHouseBaseInfo.IsTrust)
        {
            strHouseInfo.Append("有");
        }
        else
        {
            strHouseInfo.Append("无");
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">备案编号： ");
        if (string.IsNullOrEmpty(entHouseBaseInfo.MarkCode))
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(entHouseBaseInfo.MarkCode);
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2a fl\">查/跟： ");
        if (entHouseBaseInfo.HitNum == null || entHouseBaseInfo.HitNum == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.HitNum));
        }
        strHouseInfo.Append("/");
        if (entHouseBaseInfo.TraceNum == null || entHouseBaseInfo.TraceNum == 0)
        {
            strHouseInfo.Append("--");
        }
        else
        {
            strHouseInfo.Append(Convert.ToString(entHouseBaseInfo.TraceNum));
        }
        strHouseInfo.Append("</li>");

        strHouseInfo.Append("<li class=\"wid2b fl\">最后跟进日期： ");
        if (entHouseBaseInfo.ServiceTime != null)
        {
            strHouseInfo.Append(entHouseBaseInfo.ServiceTime.Value.ToLongDateString());
        }
        strHouseInfo.Append("</li>");
        strHouseInfo.Append("<li class=\"wid2a fl\">建档时间： ");
        strHouseInfo.Append(entHouseBaseInfo.Adddate.Value.ToString());
        strHouseInfo.Append("</li>");
        // strHouseInfo.Append("<li class=\"wid2 fl\"></li>");
        //strHouseInfo.Append("<li class=\"wid2b fl\"></li>");
        //strHouseInfo.Append("<li class=\"wid2 fl\"></li>");
        strHouseInfo.Append("</ul>");


        ltHouseInfo.Text = strHouseInfo.ToString();
    }

    private void setViewOwnerInfo(string HouseId)
    {
        //获取查看过房源业主的人的信息
        List<Chenxin.Lib.House.Entity.House_ViewOwerInfo> lsViewOwerInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetViewOwnerInfo(HouseId);
        Chenxin.Lib.House.Entity.House_ViewOwerInfo entViewOwerInfo;

        StringBuilder strOwerInfo = new StringBuilder();

        if (lsViewOwerInfo != null && lsViewOwerInfo.Count > 0)
        {

            for (int idxCnt = 0; idxCnt < lsViewOwerInfo.Count && idxCnt < 6; idxCnt++)
            {
                entViewOwerInfo = lsViewOwerInfo[idxCnt];

                strOwerInfo.Append("<tr class=\"tab_line6\">");
                strOwerInfo.Append("<td width=\"37%\">");
                strOwerInfo.Append("<img src=\"/images/pic_img.gif\" width=\"42\" height=\"50\" />");
                strOwerInfo.Append("</td>");
                strOwerInfo.Append("<td>");
                strOwerInfo.Append("<p>");
                strOwerInfo.Append(entViewOwerInfo.Employee);
                strOwerInfo.Append("</p>");
                strOwerInfo.Append("<p>");
                strOwerInfo.Append(entViewOwerInfo.Addtime.ToString());
                strOwerInfo.Append("</p>");
                strOwerInfo.Append("</td>");
                strOwerInfo.Append("</tr>");
            }
        }

        ltOwerInfo.Text = strOwerInfo.ToString();
    }

    private void setHidHouseInfo(Chenxin.Lib.House.Entity.House_BaseInfo entHouseBaseInfo)
    {
        hidAddress.Value = entHouseBaseInfo.Address;
        hidHouseCode.Value = entHouseBaseInfo.HouseCode;
        hidStatus.Value = entHouseBaseInfo.Status.ToString();
        hidCommunity.Value = entHouseBaseInfo.Community;
        hidBuildingName.Value = entHouseBaseInfo.BuildingName;
        hidRoom.Value = entHouseBaseInfo.Room;
        hidIsProtectPhone.Value = entHouseBaseInfo.IsProtectPhone.ToString();
        hidDisplayPhone.Value = entHouseBaseInfo.DisplayPhone;
        hidcbrAddress.Value = entHouseBaseInfo.Community + entHouseBaseInfo.BuildingName + entHouseBaseInfo.Room;
        hidCustomerId.Value = entHouseBaseInfo.CustomerId.ToString();
        hidCityId.Value = entHouseBaseInfo.CityId.ToString();
        hidCompanyId.Value = entHouseBaseInfo.CompanyId.ToString();
    }

    private void setHousePic(string houseid)
    {
        string httpPath = System.Configuration.ConfigurationManager.AppSettings["Picture.RootUrl"];
        string fallPath = "";
        List<Chenxin.Lib.House.Entity.House_PicturesInfo> pic_list = Chenxin.Lib.House.DAL.House_PicturesInfo.GetListArray("HouseId='" + houseid + "'");
        string innerHtml = "";
        foreach (Chenxin.Lib.House.Entity.House_PicturesInfo pic in pic_list)
        {
            fallPath = httpPath + pic.ThumbnailUrl;
            innerHtml += "<li><img src='" + fallPath + "' width='162' height='125' alt='" + pic.PicType + "' /></li>";
        }
        //string innerHtml = "<li><img src='http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/75/199481072_b4a0d09597_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/57/199481087_33ae73a8de_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/77/199481108_4359e6b971_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/58/199481218_264ce20da0_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/69/199481255_fdfe885f87_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg' width='162' height='125' alt='' /></li>" +
        //                "<li><img src='http://static.flickr.com/70/229228324_08223b70fa_s.jpg' width='162' height='125' alt='' /></li>";
        mycarousel.InnerHtml = innerHtml;
    }
}
